home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_48901.txt < prev    next >
Text File  |  1991-02-27  |  1KB  |  30 lines

  1. -- card: 48901 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 6
  9. ----- text -----
  10. 6.3  while/do-while
  11.  
  12. -- part contents for background part 4
  13. ----- text -----
  14. The 'while' statement implements a loop whose statement (or compound statement) is repeated until the conditional expression evaluates to 0 (false):
  15.  
  16.     while (expression)
  17.         statement
  18.  
  19. In the following example the null statement is used, since the side effect of evaluating the expression implements all the desired processing:
  20.  
  21.     while (!mouse_button_is_down())
  22.         ;
  23.  
  24. An interesting application of the comma operator mentioned earlier in this chapter is to evaluate a sequence of expressions in place of the usual condition.  The expressions are evaluated left to right, and the loop continues until the rightmost expression is false.  In the following example the side effect of the leftmost expression is assigning a value to the character variable c.  (The standard library function getchar() returns the next character from the standard input device.)
  25.  
  26.     
  27.  
  28. -- part contents for background part 7
  29. ----- text -----
  30. 161